<?php
namespace app\applet\model;
use think\Db;
use think\Model;

class HouseKeeper extends Model {
    protected $table = "house_keeper";

    /**
     * HouseKeeper constructor.
     * @param array $data
     */
    public function __construct($data = [])
    {
//        parent::__construct($data);
    }

    /**
     * @param $data
     * @return int|string
     */
    public function m_insert($data) {
        $data = Db::name($this->table)
            ->insert($data);
        return Db::name($this->table)->getLastInsID();
    }

    /**
     * 编辑
     * @param $data
     * @return int|string
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function m_update($id, $data) {
        $data = Db::name($this->table)
            ->where(['id'=>$id])
            ->update($data);
        return $data;
    }

    /**
     * 唯一性
     * @param $tel
     * @return int|string
     * @throws \think\Exception
     */
    public function uniqueness($tel) {
        $data = Db::name($this->table)
            ->where(['tel'=>$tel])
            ->find();
        return $data;
    }

    /**
     *
     * @param $tel
     * @return int|string
     * @throws \think\Exception
     */
    public function detail($id) {
        $data = Db::name($this->table)
            ->where(['id'=>$id])
            ->find();
        return $data;
    }

    /**
     * @param $openid
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function detailOpenId($openid) {
        $data = Db::name($this->table)
            ->where(['open_id'=>$openid])
            ->find();
        return $data;
    }
}